package com.sailfish.springbootdemo.dao.db7;

import com.sailfish.springbootdemo.common.DB7TableName;
import com.sailfish.springbootdemo.pojo.db7.TbFlowCompManufacturer;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface TbFlowCompManufacturerDao {
    @Select("<script>" +
            "select " +
            "* " +
            "from " + DB7TableName.TB_FLOW_COMP_MANUFACTURER + " " +
            "where flow_no = #{flowNo} and flow_level = #{flowLevel}" +
            "</script>"
    )
    List<TbFlowCompManufacturer> getTbFlowCompManufacturerByFlowNo(@Param("flowNo") String flowNo,
                                                                   @Param("flowLevel") Integer flowLevel);

    @Insert("<script>" +
            "insert into " + DB7TableName.TB_FLOW_COMP_MANUFACTURER + " " +
            "( "+
            "flow_no, " +
            "flow_level, " +
            "create_time, " +
            "create_user, " +
            "manufacturer, " +
            "manufacturer_type, " +
            "weight, " +
            "coplanarity, " +
            "standoff, " +
            "solder_tg_max, " +
            "bga_height_min, " +
            "unbd_thickness_min, " +
            "board_thickness_min, " +
            "board_thickness_max, " +
            "is_secd_reflow_drop, " +
            "thermal_contact_dimension, " +
            "comp_resource, " +
            "data_sources, " +
            "comp_code " +
            ")"+
            "values "+
            "<foreach collection=\"entities\" item=\"entity\" separator=\",\">" +
            "(" +
            "#{entity.flow_no}, " +
            "#{entity.flow_level}, " +
            "#{entity.create_time}, " +
            "#{entity.create_user}, " +
            "#{entity.manufacturer}, " +
            "#{entity.manufacturer_type}, " +
            "#{entity.weight}, " +
            "#{entity.coplanarity}, " +
            "#{entity.standoff}, " +
            "#{entity.solder_tg_max}, " +
            "#{entity.bga_height_min}, " +
            "#{entity.unbd_thickness_min}, " +
            "#{entity.board_thickness_min}, " +
            "#{entity.board_thickness_max}, " +
            "#{entity.is_secd_reflow_drop}, " +
            "#{entity.thermal_contact_dimension}, " +
            "#{entity.comp_resource}, " +
            "#{entity.data_sources}," +
            "#{entity.comp_code} " +
            ")"+
            "</foreach>"+
            "</script>"
    )
    Integer insertTbFlowCompManufacturerBatch(@Param("entities") List<TbFlowCompManufacturer> entities);

    @Update("<script>" +
            "update " + DB7TableName.TB_FLOW_COMP_MANUFACTURER + " " +
            "set " +
            " <if test='entity.manufacturer != null'>manufacturer = #{entity.manufacturer},</if>" +
            " <if test='entity.manufacturer_type != null'>manufacturer_type = #{entity.manufacturer_type},</if>" +
            " <if test='entity.weight != null'>weight = #{entity.weight},</if>" +
            " <if test='entity.coplanarity != null'>coplanarity = #{entity.coplanarity},</if>" +
            " <if test='entity.standoff != null'>standoff = #{entity.standoff},</if>" +
            " <if test='entity.solder_tg_max != null'>solder_tg_max = #{entity.solder_tg_max},</if>" +
            " <if test='entity.bga_height_min != null'>bga_height_min = #{entity.bga_height_min},</if>" +
            " <if test='entity.unbd_thickness_min != null'>unbd_thickness_min = #{entity.unbd_thickness_min},</if>" +
            " <if test='entity.board_thickness_min != null'>board_thickness_min = #{entity.board_thickness_min},</if>" +
            " <if test='entity.board_thickness_max != null'>board_thickness_max = #{entity.board_thickness_max},</if>" +
            " <if test='entity.is_secd_reflow_drop != null'>is_secd_reflow_drop = #{entity.is_secd_reflow_drop},</if>" +
            " <if test='entity.thermal_contact_dimension != null'>thermal_contact_dimension = #{entity.thermal_contact_dimension},</if>" +
            " <if test='entity.comp_resource != null'>comp_resource = #{entity.comp_resource},</if>" +
            " <if test='entity.data_sources != null'>data_sources = #{entity.data_sources},</if>" +
            " <if test='entity.comp_code != null'>comp_code = #{entity.comp_code},</if>" +
            " update_time = #{entity.update_time}," +
            " update_user = #{entity.update_user}" +
            " where id = #{entity.id}" +
            //"where flow_no = #{entity.flow_no} and flow_level = #{entity.flow_level}" +
            "</script>"
    )
    Integer updateTbFlowCompManufacturer(@Param("entity") TbFlowCompManufacturer entity);

    @Update("<script>" +
            "update " + DB7TableName.TB_FLOW_COMP_MANUFACTURER + " " +
            "set " +
            " <if test='entity.manufacturer != null'>manufacturer = #{entity.manufacturer},</if>" +
            " <if test='entity.manufacturer_type != null'>manufacturer_type = #{entity.manufacturer_type},</if>" +
            " <if test='entity.weight != null'>weight = #{entity.weight},</if>" +
            " <if test='entity.coplanarity != null'>coplanarity = #{entity.coplanarity},</if>" +
            " <if test='entity.standoff != null'>standoff = #{entity.standoff},</if>" +
            " <if test='entity.solder_tg_max != null'>solder_tg_max = #{entity.solder_tg_max},</if>" +
            " <if test='entity.bga_height_min != null'>bga_height_min = #{entity.bga_height_min},</if>" +
            " <if test='entity.unbd_thickness_min != null'>unbd_thickness_min = #{entity.unbd_thickness_min},</if>" +
            " <if test='entity.board_thickness_min != null'>board_thickness_min = #{entity.board_thickness_min},</if>" +
            " <if test='entity.board_thickness_max != null'>board_thickness_max = #{entity.board_thickness_max},</if>" +
            " <if test='entity.is_secd_reflow_drop != null'>is_secd_reflow_drop = #{entity.is_secd_reflow_drop},</if>" +
            " <if test='entity.thermal_contact_dimension != null'>thermal_contact_dimension = #{entity.thermal_contact_dimension},</if>" +
            " <if test='entity.comp_resource != null'>comp_resource = #{entity.comp_resource},</if>" +
            " <if test='entity.data_sources != null'>data_sources = #{entity.data_sources},</if>" +
            " <if test='entity.comp_code != null'>comp_code = #{entity.comp_code},</if>" +
            " update_time = #{entity.update_time}," +
            " update_user = #{entity.update_user}" +
            //" where id = #{entity.id}" +
            " where flow_no = #{entity.flow_no} and flow_level = #{entity.flow_level}" +
            "</script>"
    )
    Integer updateTbFlowCompManufacturer2(@Param("entity") TbFlowCompManufacturer entity);

    @Delete("<script>" +
            "delete from " + DB7TableName.TB_FLOW_COMP_MANUFACTURER + " " +
            "where flow_no = #{flowNo} and flow_level = #{flowLevel}" +
            "</script>"
    )
    Integer deleteTbFlowCompManufacturer(@Param("flowNo") String flowNo, @Param("flowLevel") Integer flowLevel);

    @Delete("<script>" +
            "delete from " + DB7TableName.TB_FLOW_COMP_MANUFACTURER + " " +
            "where flow_no = #{flowNo}" +
            "</script>"
    )
    Integer deleteTbFlowCompManufacturerByFlowNo(@Param("flowNo") String flowNo);

    @Delete("<script>" +
            "delete from " + DB7TableName.TB_FLOW_COMP_MANUFACTURER + " " +
            "where  data_sources is NULL and id = #{id}" +
            "</script>"
    )
    Integer deleteTbFlowCompManufacturerById(@Param("id") Integer id);

}
